package com.kingdee.eas.custom.hr.affair.fluctuation.client;

import java.util.List;

import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.eas.basedata.org.PositionMemberCollection;
import com.kingdee.eas.basedata.org.PositionMemberInfo;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.custom.common.PersonUtil;
import com.kingdee.eas.custom.hr.affair.fluctuation.OuterFluctuationOrgChangeEntryInfo;
import com.kingdee.eas.custom.hr.base.AttendanceCodeInfo;
import com.kingdee.eas.custom.hr.base.DirectAndIndirectInfo;
import com.kingdee.eas.hr.affair.AffairBatchProcessFacadeFactory;
import com.kingdee.eas.hr.base.batch.BatchProcessedResult;
import com.kingdee.eas.hr.base.client.HRBillEditUIBiz;
import com.kingdee.eas.hr.base.client.IHRF7CommonRegister;
import com.kingdee.eas.hr.canon.cbase.AdminOrgBaseInfo;
import com.kingdee.eas.hr.canon.cbase.GradeInfo;
import com.kingdee.eas.hr.emp.PersonPositionInfo;
import com.kingdee.eas.util.client.MsgBox;

public class OuterFluctuationOrgChangeEditUIBiz extends HRBillEditUIBiz {

	protected List getProcessedPersons(List persons, String billID)
			throws Exception {
		BatchProcessedResult result = AffairBatchProcessFacadeFactory
				.getRemoteInstance().processPerson(persons, billID);

		if (result == null) {
			return null;
		}
		if (result.isHasValidInfo()) {
			MsgBox.showInfo(result.getInvalidInfo());
		}
		List processedPerson = result.getResult();
		return processedPerson;
	}

	@Override
	protected IObjectValue createNewDetailData(PersonInfo person) {
		OuterFluctuationOrgChangeEntryInfo info = new OuterFluctuationOrgChangeEntryInfo();
		info.setPerson(person);
		info.setNumber(person.getNumber());
		info.setName(person.getName());

		PersonPositionInfo personPosition = (PersonPositionInfo) person
				.get("personPosition");
		if (personPosition != null) {
			info.setNowAdminOrg(personPosition.getPersonDep());
			info.setTargetAdminOrgUnit(personPosition.getPersonDep());
		}

		PositionMemberCollection memberCollection = (PositionMemberCollection) person
				.get("PositionMember");
		for (int i = 0; i < memberCollection.size(); i++) {
			PositionMemberInfo positionMember = memberCollection.get(i);
			if (positionMember.isIsPrimary()) {
				info.setNowPosition(positionMember.getPosition());
				info.setNowJob(positionMember.getPosition().getJob());
			}
		}

		try {
			PersonInfo p = PersonUtil.getPersonInfo(new ObjectUuidPK(person
					.getId()), "adminOrgBase.*", "grade.*",
					"directAndIndirectDiff.*", "attendanceCode.*");
			AdminOrgBaseInfo adminOrgBase = p.getAdminOrgBase();
			if (adminOrgBase != null) {
				info.setNowAdminBase(adminOrgBase);
			}

			GradeInfo grade = p.getGrade();
			if (grade != null) {
				info.setNowGrade(grade);
			}
			
			DirectAndIndirectInfo direct = p.getDirectAndIndirectDiff();
			if (direct != null) {
				info.setNowDirectDiff(direct);
			}
			
			AttendanceCodeInfo  attendanceCode = p.getAttendanceCode();
			if (attendanceCode != null) {
				info.setNowAttendCode(attendanceCode);
//				info.setnow (attendanceCode);
			}
		} catch (Exception e) {
			this.handUIException(e);
		}

		return info;
	}

	@Override
	protected boolean isAddPersonByF7() {
		return true;
	}

	@Override
	public void initDataStatus() throws Exception {
		super.initDataStatus();
	}

	@Override
	protected void initEditor() throws Exception {

	}

	@Override
	public void registerContextChangeF7(IHRF7CommonRegister register) {
		super.registerContextChangeF7(register);
		register
				.registerAdminByOrgRangePromptBox(((OuterFluctuationOrgChangeEditUI) this.ctx
						.getUI()).prmtAdminOrg);
	}

	@Override
	protected String[] getNotNullColumn() {
		return new String[] {};
	}

	@Override
	protected boolean isNeedSetLockColumnColor() {
		return true;
	}

	@Override
	protected boolean isNeedSetNotNullColumnColor() {
		return true;
	}
}
